package com.yukefms.jointpoint;

import com.yukefms.jointpoint.interfaces.Position;

import java.io.Serializable;
import java.util.Objects;

/**
 * The joint represents body point, which is measured by the position, i.e, 2D or 3D.
 * @author  Ping
 * @date 2021-6-15
 */
public class Joint implements Serializable {
    private String jointType ;
    private JointStatus jointStatus ;
    private Position position ;

    public Joint() {
    }
    public Joint(String ... vals) {
        if (vals.length < 5) {
            throw new IllegalArgumentException("Joint construction needs five arguments, but four.") ;
        }
        this.jointType = vals[0] ;
        this.position = new D3Position(Double.parseDouble(vals[1])
                                              ,Double.parseDouble(vals[2])
                                              ,Double.parseDouble(vals[3])) ;
        this.jointStatus = JointStatus.toStatus(vals[4]) ;

    }
    public Joint(String jointType, JointStatus jointStatus, Position position) {
        this.jointType = jointType;
        this.jointStatus = jointStatus;
        this.position = position;
    }

    /**
     * check whether the position is tracked or not.
     * @return
     */
    public boolean isTracked() {
        return this.jointStatus == JointStatus.Tracked  || this.jointStatus == JointStatus.Inferred ;
    }
    public String getJointType() {
        return jointType;
    }

    public void setJointType(String jointType) {
        this.jointType = jointType;
    }

    public int getJointStatus() {
        return jointStatus.ordinal();
    }

    public void setJointStatus(JointStatus jointStatus) {
        this.jointStatus = jointStatus;
    }

    public Position getPosition() {
        return position;
    }

    public void setPosition(Position position) {
        this.position = position;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Joint)) {
            return false;
        }
        Joint joint = (Joint) o;
        return jointStatus == joint.jointStatus &&
                Objects.equals(jointType, joint.jointType) &&
                Objects.equals(position, joint.position);
    }

    @Override
    public int hashCode() {
        return Objects.hash(jointType, jointStatus, position);
    }

    @Override
    public String toString() {
        return "Joint{" +
                "jointType='" + jointType + '\'' +
                ", jointStatus=" + jointStatus +
                ", position=" + position +
                '}';
    }
}
